#include "../include/errors.hpp"
#include <cstdlib>


void soulc::raiseError(soulc::Error error, std::string additionalText)
{
	std::cout << termcolor::red << soulc::errorTexts.at(error) << termcolor::reset << " (" << additionalText << ")\n";

	std::exit(error);
}
void soulc::raiseError(soulc::Error error)
{
	std::cout << termcolor::red << soulc::errorTexts.at(error) << termcolor::reset << "\n";
	
	std::exit(error);
}

void soulc::raiseCompilerError(soulc::CompilerError error, uint64_t line, uint64_t symbol, std::string erroneousCode)
{
	std::cout << termcolor::red << soulc::compilerErrorTexts.at(error) << termcolor::reset << ":\n";
	std::cout << '\t' << erroneousCode << "\n\t";

	for (uint64_t i = 0; i < symbol; i++) { std::cout << " "; }

	std::cout << termcolor::red << '^' << termcolor::reset << '\n';

	std::exit(error);
}

void soulc::raiseCompilerError(soulc::CompilerError error, uint64_t lineNo, uint64_t symbolNo, std::string erroneousCode, std::string additionalText)
{
	std::cout << "[" << lineNo << ":" << symbolNo << "] " << termcolor::red << soulc::compilerErrorTexts.at(error) << termcolor::reset << '(' << additionalText << "):\n";
	std::cout << "" << str::trim(erroneousCode) << "\n";

	std::exit(error);
}
